package utils

import (
	"fmt"
	"gopkg.in/ini.v1"
)

var (
	AppMode    string
	HttpPort   string
	JwtKey     string
	DbType     string
	DbHost     string
	DbPort     string
	DbUser     string
	DbPassWord string
	DbName     string
	AccessKey  string
	Secretkey  string
	Bucket     string
	ServerHost string
)

func init() {
	file, err := ini.Load("./config/config.ini")

	if err != nil {
		fmt.Println(" config init error")
	}

	loadServer(file)
	loadDatabase(file)
	loadOss(file)
}

//  load gin config from config.ini
func loadServer(file *ini.File) {
	section := file.Section("server")

	AppMode = section.Key("AppMode").MustString("debug")
	HttpPort = section.Key("HttpPort").MustString(":3000")
	JwtKey = section.Key("JwtKey").MustString("mixinju")
}

// load database config from config.ini
func loadDatabase(file *ini.File) {
	section := file.Section("database")

	DbType = section.Key("DbType").MustString("mysql")
	DbHost = section.Key("DbHost").MustString("127.0.0.1")
	DbPort = section.Key("DbPort").MustString("3306")
	DbUser = section.Key("DbUser").MustString("mixinju")
	DbPassWord = section.Key("DbPassWord").MustString("123456")
	DbName = section.Key("DbName").MustString("DbName")
}

// 加载Oss 配置相关
func loadOss(f *ini.File) {
	s := f.Section("oss")
	AccessKey = s.Key("AccessKey").MustString("")
	Secretkey = s.Key("Secretkey").MustString("")
	Bucket = s.Key("Bucket").MustString("")
	ServerHost = s.Key("ServerHost").MustString("")
}
